<template>
    <div>
        <el-dialog
        :visible.sync="dataPreviewVisible.v"
        :title="title"
        v-dialogDrag>
            <div style="padding: 20px 0px 20px 0">
                <el-radio-group v-model="radio"  size="mini">
                    <el-radio-button label="字段"></el-radio-button>
                    <el-radio-button label="数据"></el-radio-button>
                </el-radio-group>
            </div>
            <dataInfoTable :tableData="dataInfoData" v-show="dataInfoTableShow"></dataInfoTable>
            <dataTable :tableInData="dataTableData" v-show="dataTableShow"></dataTable>
        </el-dialog>
    </div>
</template>

<script>
    import dataInfoTable from '../../components/table/dataInfoTable';
    import  dataTable from '../../components/table/dataTable'

    export default {
        name: "",
        data(){
            return{
                dataInfoTableShow:true,
                dataTableShow:false,
                radio:'字段',
                dataPreviewVisible:Object,
                artifactId:String,
                title:'',
                dataInfoData:[],
                dataTableData:[],
                totalData:[]
            }
        },
        props:{

        },
        components:{
            "dataInfoTable":dataInfoTable,
            "dataTable":dataTable
        },
        methods:{
            showData(dataType,dataId){
                let that = this;
                let useId = '';
                let dataInfoData = [];
                this.$axios.get('/data/list?offset=0&size=500').then(function (res) {
                    if(res.body.data){
                        for(let publicData of res.body.data){
                            that.totalData.push(publicData.data);
                        }
                    }
                }).catch(function (error) {
                    console.log(error)
                });
                this.$axios.get('/user/data?offset=0&size=500').then(function(perRes){
                    if(perRes.body.data){
                        for(let personData of perRes.body.data){
                            that.totalData.push(personData.data);
                        }
                    }
                }).catch(function(error){
                    console.log(error)
                });
                console.log(that.totalData)
                for(let idArr of that.totalData){
                    if(dataId == idArr.meta_name){
                        useId = idArr.pk_meta_id;
                        that.dataInfoData = idArr;
                        console.log(that.dataInfoData)
                        if(useId!==''){
                            that.$axios.get('/data/preview/'+ useId +'?offset=0&size=100').then(function (res) {
                                that.dataTableData = res.body;
                                console.log(res.body)
                            }).catch(function (error) {
                                console.log(error)
                            });
                        }
                    }
                }
                if(dataType == '字段'){
                    that.dataTableShow = false;
                    that.dataInfoTableShow = true;
                }else if(dataType == '数据'){
                    that.dataInfoTableShow = false;
                    that.dataTableShow = true;
                }
            },
        },
        mounted(){
            let that = this;
            this.$Bus.$on('dataDialogParams',(previewVisible,artifactId)=>{
                this.dataPreviewVisible = previewVisible;
                this.artifactId = artifactId;
                this.title = artifactId;
                console.log(this.artifactId);
                that.showData(that.radio,that.artifactId);
            });

        },
        watch:{
            radio:function () {
                this.showData(this.radio,this.artifactId)
            }
        }
    }
</script>

<style scoped>

</style>